﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Xejen.Hosting
{
    /// <summary>
    /// 表示主机配置
    /// </summary>
    /// <creator>marc</creator>
    public class HostConfiguration
    {
        /// <summary>
        /// 默认配置文件名
        /// </summary>
        public string DefaultSettingsFileName { get; set; } = "appsettings.json";

        /// <summary>
        /// 配置文件加载目录
        /// </summary>
        public string ConfigDirectory { get; set; } = AppDomain.CurrentDomain.BaseDirectory;

        /// <inheritdoc cref="HostConfiguration"/>
        public HostConfiguration() { }

        /// <summary>
        /// 从命令参数加载并创建<see cref="HostConfiguration"/>实例
        /// </summary>
        /// <param name="args">命令参数</param>
        /// <returns></returns>
        public static HostConfiguration Load(string[] args)
        {
            var config = new HostConfiguration();
            foreach (var arg in args)
            {
                if (arg.StartsWith("--config-directory="))
                {
                    config.ConfigDirectory = arg.Substring("--config-directory=".Length);
                }
            }
            return config;
        }
    }
}
